package com.lili.math;

import java.util.*;

/**
 * @Auther: 李 力
 * @Date: 2024/7/30
 * @Description: 自除数
 * @version: 1.0
 */
public class LeetCode728 {

    /*
     * 时间复杂度: O(n^2)
     * 空间复杂度:O(1)
     */
    public static List<Integer> selfDividingNumbers(int left, int right) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int start = left; start <= right; start++) {
            int curr = start;
            int temp = start;
            int count1 = 0;
            int count2 = 0;
            while (temp != 0) {
                int num = temp % 10;
                if (num != 0 && curr % num == 0) {
                    count2++;
                }
                temp = temp / 10;
                count1++;
            }
            if (count1 == count2) {
                list.add(curr);
            }
        }
        return list;
    }
}
